﻿Imports HMSLibrary
Imports HMSDataLayer
Imports WpfCheckListBox
Imports System.Collections.ObjectModel

Public Class PatientFindingsWindow

    Public Property findingList As ObservableCollection(Of PatientExamFinding)
    Private Sub MasterWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        findingList = New ObservableCollection(Of PatientExamFinding)
        AddNew()
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Public Sub AddNew()
        Dim dataProvider As New MasterDataLayer()
        Dim lst As List(Of Lookups)
        lst = dataProvider.GetLookupList(LookupTypes.FindingCategory)
        FindingCategoryListBox.ItemsSource = lst
        FindingsDataGrid.ItemsSource = findingList
    End Sub

    Dim _Items As ObservableCollection(Of CheckedListBoxItem)
    Private Sub FindingCategoryListBox_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles FindingCategoryListBox.SelectionChanged
        If FindingCategoryListBox.SelectedItem Is Nothing Then Exit Sub
        Dim dataProvider As New MasterDataLayer()
        Dim lst As List(Of Finding)
        lst = dataProvider.GetFindingsCategoryList(e.AddedItems(0).ID)
        _Items = New ObservableCollection(Of CheckedListBoxItem)

        For Each item In lst
            _Items.Add(New CheckedListBoxItem(item.Name, item.ID, False))
        Next
        FindingCheckedListBox.ListBox.ItemsSource = _Items
    End Sub

    Private Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CancelButton.Click
        findingList = Nothing
        Me.Close()
    End Sub

    Private Sub OKButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles OKButton.Click
        Me.Close()
    End Sub

    Private Sub AddFindingsButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddFindingsButton.Click
        If FindingCategoryListBox.SelectedItem Is Nothing Then Exit Sub
        Dim find As Lookups = FindingCategoryListBox.SelectedItem
        For Each it As CheckedListBoxItem In _Items
            If it.IsChecked = True Then
                Dim pFind As New PatientExamFinding
                pFind.findCategory = find.ID
                pFind.findCategoryName = find.Name
                pFind.findings = it.ValueMember
                pFind.findingsName = it.DisplayMember
                findingList.Add(pFind)
            End If
        Next

    End Sub

    Private Sub AddNewFindingButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddNewFindingButton.Click
        Dim win As New MasterWindow
        win.FormType = FormsList.Findings
        win.ShowDialog()
    End Sub
End Class
